package com.rongshe.web.controller.hotel;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rongshe.common.annotation.Log;
import com.rongshe.common.core.controller.BaseController;
import com.rongshe.common.core.domain.AjaxResult;
import com.rongshe.common.enums.BusinessType;
import com.rongshe.hotel.domain.RsHotel;
import com.rongshe.hotel.service.IRsHotelService;
import com.rongshe.common.utils.poi.ExcelUtil;
import com.rongshe.common.core.page.TableDataInfo;

/**
 * 民宿Controller
 * 
 * @author rongshe
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/hotel/hotel")
public class RsHotelController extends BaseController
{
    @Autowired
    private IRsHotelService rsHotelService;

    /**
     * 查询民宿列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hotel:list')")
    @GetMapping("/list")
    public TableDataInfo list(RsHotel rsHotel)
    {
        startPage();
        List<RsHotel> list = rsHotelService.selectRsHotelList(rsHotel);
        return getDataTable(list);
    }

    /**
     * 导出民宿列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hotel:export')")
    @Log(title = "民宿", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RsHotel rsHotel)
    {
        List<RsHotel> list = rsHotelService.selectRsHotelList(rsHotel);
        ExcelUtil<RsHotel> util = new ExcelUtil<RsHotel>(RsHotel.class);
        util.exportExcel(response, list, "民宿数据");
    }

    /**
     * 获取民宿详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rsHotelService.selectRsHotelById(id));
    }

    /**
     * 新增民宿
     */
    @PreAuthorize("@ss.hasPermi('hotel:hotel:add')")
    @Log(title = "民宿", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RsHotel rsHotel)
    {
        return toAjax(rsHotelService.insertRsHotel(rsHotel));
    }

    /**
     * 修改民宿
     */
    @PreAuthorize("@ss.hasPermi('hotel:hotel:edit')")
    @Log(title = "民宿", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RsHotel rsHotel)
    {
        return toAjax(rsHotelService.updateRsHotel(rsHotel));
    }

    /**
     * 删除民宿
     */
    @PreAuthorize("@ss.hasPermi('hotel:hotel:remove')")
    @Log(title = "民宿", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rsHotelService.deleteRsHotelByIds(ids));
    }
}
